import React from "react";
import { Button, Table, Select, Form, DatePicker, Modal, Input, Space, } from "antd";
import { connect } from "react-redux";
import * as actions from "./store/action";
import QueryWarning from './component/QueryWarning';
import DataTable from './component/DataTable'
import Websocket from "../../component/Websocket/websocket";
const { RangePicker } = DatePicker;
class Index extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            tableStatus: 'default', //default-默认，query-查询
            status:'疑似',
            pending: '',//待处理的告警数
            processed: '',//已处理的告警数
            information: "", //告警详情内容
            pageIndex: 1, //默认页面为第一页
            pageSize: 10,
            alarm: "",
            LinerWarning: [],
            tableStatus: 'default', //default-默认，query-查询
            queryAdress: {}, //更具地址的查询条件
        };
    }
    componentDidMount() {
        let page = {
            pageIndex: this.state.pageIndex - 1,
            pageSize: this.state.pageSize,
        };
        this.props.getWarningBypatroller(page);
        this.props.getCounter()
    }
   

    render() {
        const { LinerWarning = [],totalCount } = this.props;
        const { pageIndex, pageSize } = this.state;
        return (
            <div>
                <Websocket id={"Lineinspectoralarm"} />
                <div>
                    <QueryWarning
                        handleQueryByAdress={(values) => {
                            this.setState({
                                tableStatus: 'query',
                                queryAdress: values,
                                pageIndex: 1,
                                pageSize: 10,
                            })
                            this.props.getWarningByTypeStatusTime(values)
                        }}
                        handleResetQuery={() => {
                            this.setState({
                                tableStatus: 'default',
                                queryAdress: {},
                                pageIndex: 1,
                                pageSize: 10,
                            })
                            this.props.getWarningBypatroller({ pageIndex: 0, pageSize: 10 })
                        }}
                        handleQueryByStatus={(value) => {
                            this.setState({
                                tableStatus: '',
                                status:value
                            })
                            this.props.getSuspectedStatus(value)
                        }}
                        onSearchAfter={(value) => {
                            this.onSearchAfter(value)
                        }} />
                </div>
                <div>
                    <DataTable
                        LinerWarning={LinerWarning}
                        pageSize={pageSize}
                        pageIndex={pageIndex}
                        totalCount={totalCount}
                        handlePageChange={this.handlePageChange}
                        getDetails={this.getDetails}
                    />
                </div>
            </div>
        );
    }
    // 表格页面或页数改变
    handlePageChange = (pageIndex, pageSize) => {
        this.setState({
            pageIndex,
            pageSize
        })
        if (this.state.tableStatus === "default") {
            this.props.getWarningBypatroller({ pageIndex: pageIndex - 1, pageSize })
        } else if(this.state.tableStatus === "query") {
            let obj = this.state.queryAdress;
            obj.pageIndex = pageIndex - 1
            obj.pageSize = pageSize
            this.props.getWarningByTypeStatusTime(obj)
        }else if (this.state.tableStatus === ""){
            let status=this.state.status
            this.props.getSuspectedStatus(status)
        }
    }
}
const mapStateToProps = (state) => ({
    //获取巡线工个人告警信息
    LinerWarning: state.getLinerWarning.LinerWarning,
    treatedDataSize: state.getLinerWarning.treatedDataSize,
    untreatedDataSize: state.getLinerWarning.untreatedDataSize,
    totalCount: state.getLinerWarning.totalCount
});

const mapDispatchToProps = (dispatch) => ({
    //获取巡线工个人告警信息
    getWarningBypatroller(page) {
        dispatch(actions.getWarningBypatroller(page));
    },
    //根据状态类型时间获取告警信息
    getWarningByTypeStatusTime(information) {
        dispatch(actions.getWarningByASTTMD(information));
    },
    //反馈
    feedBack(details, pageIndex) {
        dispatch(actions.feedBack(details, pageIndex));
    },
    getSuspectedStatus(information) {
        dispatch(actions.getSuspectedStatus(information))
    },
    getCounter(){
        dispatch(actions.getCounter())
    }
});

export default connect(mapStateToProps, mapDispatchToProps)(Index);
